package com.hl.web.fore;

import com.hl.pojo.Course;
import com.hl.service.CourseService;
import com.hl.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private CourseService service;

    @PostMapping("/add")
    public ResultEntity addCourse(@RequestBody Course course) {
        service.addCourse(course);
        return ResultEntity.ok();
    }

    @PostMapping("/update")
    public ResultEntity updateCourse(@RequestBody Course course) {
        service.updateCourse(course);
        return ResultEntity.ok();
    }


    @GetMapping("/del")
    public ResultEntity deleteCourse(Integer id) {
        service.deleteCourse(id);
        return ResultEntity.ok();
    }

    @GetMapping("/findById")
    public ResultEntity findCourseById(Integer id) {
        return ResultEntity.ok(service.findCourseById(id));
    }

    @GetMapping("/findAll")
    public ResultEntity findAllCourses() {
        return ResultEntity.ok(service.findAllCourses());
    }

    @GetMapping("/findByCourseName")
    public ResultEntity findByCourseName(String courseName) {
        return ResultEntity.ok(service.findByCourseName(courseName));
    }
}
